<?php

class Admin_AttendanceController extends Zend_Controller_Action {

    protected $_flashMessenger = null;

    public function init() {
        $auth = Zend_Auth::getInstance ();
        if ($auth->hasIdentity()) {
            if ($auth->getIdentity()->role != 'administrator') {
                $this->_helper->redirector('index', 'auth', 'default');
            }
        } else {
            $this->_helper->redirector('index', 'auth', 'default');
        }
        $this->_helper->layout->setLayout('admin');
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
        $this->initView();
    }

    public function indexAction() {
    	$classid = $_GET['s_class'];
        $moClass = new Application_Model_ClassModel ();
		$class_list = $moClass->fetchAll ();
        $this->view->class_list = $class_list;
        
        $class_details = array('class_id'=>$classid,'academic_id'=>3);
        $student_list = $moClass->getStudentsListByClassId ($class_details);
        $this->view->student_list = $student_list;
        $data = $this->view->Action('leftsidebar','Index','admin');
        $this->view->leftsidebar = $data;
    }
    
    public function presentstatusAction()
    {
		$request = $this->getRequest ();
		$data = $request->getParams ();
		$student_ids = $request->getParam('student_id');
		$allstudents = $request->getParam('status');
		$all_students_status = array();
		
		foreach($student_ids as $key=>$value)
		{
			if(isset($allstudents[$value]))
			{
				$all_students_status[$value] = 1;
			}
			else
				$all_students_status[$value] = 0;
		}
		
		foreach ($all_students_status as $key => $value)
		{
			$insert['student_id'] = $key;
			$insert['status'] = $value;
			$insert['on_date'] = date('Y-m-d');
			$moClass = new Application_Model_Attendance ();
			$moClass->save($insert);
		}
    	$_redirect = $this->_redirect("/admin/attendance?s_class=".$data['class_id']);
    }
    

}

